import React from 'react'
import styles from './index.less'
// import {} from "@ant-design/pro-layout"
import { Button, Form, Input } from 'antd'
import axios from "@/request"
import { userLogin } from "@/api/login"
import { history } from 'umi'


const onFinish = async (values: any) => {
    const data = await userLogin(values)
    if (data) {
        sessionStorage.setItem('token', data.data.token)
        history.push('/ads')
    } 
};

const onFinishFailed = (errorInfo: any) => {
    console.log('Failed:', errorInfo);
};

type Props = {}


export default function index({ }: Props) {
    return (
        <div className={styles.login}>
            <div className={styles.card}>
                <Form
                    name="basic"
                    wrapperCol={{ span: 24 }}
                    initialValues={{ remember: true }}
                    onFinish={onFinish}
                    onFinishFailed={onFinishFailed}
                    autoComplete="off"
                >
                    <Form.Item
                        name="username"
                        rules={[{ required: true, message: '请输入正确名称!' }]}
                    >
                        <Input />
                    </Form.Item>

                    <Form.Item
                        name="password"
                        rules={[{ required: true, message: '请输入正确密码!' }]}
                    >
                        <Input.Password />
                    </Form.Item>

                    <Form.Item>
                        <Button style={{
                            width: "100%"
                        }} type="primary" htmlType="submit">
                            登录
                        </Button>
                    </Form.Item>
                </Form>
            </div>
        </div>
    )
}